﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Globalization;

namespace ICDA.Web.Models
{
    public class CellEditingViewModelBinder : DefaultModelBinder
    {
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            CellEditingViewModel model = new CellEditingViewModel();

            model.ID = Convert.ToInt32(controllerContext.HttpContext.Request.Params["ID"]);
            if (controllerContext.HttpContext.Request.Params.AllKeys.Contains("ID"))
            {
                model.PropertyName = "ID";
                model.PropertyValue = controllerContext.HttpContext.Request.Params["ID"];
            }
            else if (controllerContext.HttpContext.Request.Params.AllKeys.Contains("Task"))
            {
                model.PropertyName = "Task";
                model.PropertyValue = controllerContext.HttpContext.Request.Params["Task"];
            }
            else if (controllerContext.HttpContext.Request.Params.AllKeys.Contains("TimeSpend"))
            {
                model.PropertyName = "TimeSpend";
                model.PropertyValue = Convert.ToInt32(controllerContext.HttpContext.Request.Params["TimeSpend"]);
            }
            else if (controllerContext.HttpContext.Request.Params.AllKeys.Contains("OverTime"))
            {
                model.PropertyName = "OverTime";
                model.PropertyValue = Convert.ToInt32(controllerContext.HttpContext.Request.Params["OverTime"]);
            }
            else if (controllerContext.HttpContext.Request.Params.AllKeys.Contains("ActivityDate"))
            {
                model.PropertyName = "ActivityDate";
                model.PropertyValue = Convert.ToDateTime(controllerContext.HttpContext.Request.Params["ActivityDate"]);
            }
            
            return model;
        }
    }
}